Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 149dff2ee25771f26b9331ff09dc875eb69eb3dd


Parents : de35a9d
Author : jacob.eva <x00010@disroot.org>
Signature : Signature validation error
Date : 2025-01-30T16:54:34Z

Guard against BT power cycle object duplication bug

Changes

1 files changed, 8 insertions(+), 5 deletions(-)

M Bluetooth.h +8 -5

Diff

diff --git a/Bluetooth.h b/Bluetooth.h
index bbb0c82..d14284f 100644
--- a/Bluetooth.h
+++ b/Bluetooth.h
@@ -38,6 +38,7 @@
BLEUart SerialBT(BLE_RX_BUF);
BLEDis bledis;
BLEBas blebas;
+ bool SerialBT_init = false;
#endif
#define BT_PAIRING_TIMEOUT 35000
@@ -511,12 +512,14 @@ char bt_devname[11];
// start device information service
bledis.begin();
- SerialBT.bufferTXD(true); // enable buffering
+ // Guard to ensure SerialBT service is not duplicated through BT being power cycled
+ if (!SerialBT_init) {
+ SerialBT.bufferTXD(true); // enable buffering
- SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
- SerialBT.begin();
-
- blebas.begin();
+ SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
+ SerialBT.begin();
+ SerialBT_init = true;
+ }
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────